home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / mus / misc / MPEG_S_LAMEppc.lha / mpeg_s_LAME3.87 / mlame < prev    next >
Text File  |  1980-09-09  |  5KB  |  197 lines

  1. #! /bin/bash 
  2. #! /usr/local/bin/bash
  3.  
  4. ############################################################################
  5. #   
  6. #  Run the LAME encoder on multiple files, with option to delete .wav files
  7. #  after encoding.  "mlame -?" will give instructions.
  8. #
  9. #  Robert Hegemann <Robert.Hegemann@gmx.de>
  10. #  modified on request: Frank Klemm <pfk@uni-jena.de>
  11. #
  12. ############################################################################
  13.  
  14. # encoder path to use
  15. mp3coder="lame"
  16. mp3analyzer="mlame_corr"
  17.  
  18. # default options to use
  19. options_low="-h -d -mj -b 128"
  20. options_high="-h -d -mj -V 1 -b 112 -B 320"
  21. options=$options_high
  22.  
  23. # remove source?
  24. removesource=false
  25.  
  26. # force overwrite of destination
  27. testoverwrite=true
  28.  
  29. # waiting after error report n seconds
  30. errordelay=1 
  31.  
  32. helptext="\n\
  33. This script runs the LAME mp3 encoder on multiple files: \n\n\
  34.     $0 [options] <file 1> ... <file n>\n\
  35. \n\
  36.   options:\n\
  37.     -?                  this help text\n\
  38.     -r                  remove files after encoding\n\
  39.     -f                  force overwrite of destination if exists\n\
  40.     -l                  low quality settings\n\
  41.     -h                  high quality settings\n\
  42.     -o \"<lame options>\" overrides script default options
  43. \n\
  44.   example:\n\
  45.     $0  -r  -f  -o \"-v -V 0 -b 112\" a*.wav z*.aif g*.mp?\n\
  46. \n\
  47. "
  48.  
  49. #   process command-line options
  50. #   this could be extended to fake the 
  51. #   commandline interface of the mp3encoder
  52.  
  53. while getopts ":o:r:h:l:f" optn; do
  54.     case $optn in
  55.     o ) options=$OPTARG     # replace default options
  56.     echo New lame options are \'$options\'
  57.         ;; 
  58.     r ) removesource=true
  59.         echo Removing source files after successfully converting
  60.     ;;
  61.     f ) testoverwrite=false
  62.         echo Force overwriting existing destination files
  63.     ;;
  64.     h ) options=$options_high
  65.         ;;
  66.     l ) options=$options_low
  67.         ;;
  68.     \? ) printf "$helptext"
  69.     sleep $errordelay
  70.         exit 1  
  71.         ;;
  72.     esac
  73. done
  74. shift $(($OPTIND - 1))
  75.  
  76. # no files remaining?
  77.  
  78. if [ "$1" = "" ]; then
  79.     printf "$helptext"
  80.     sleep $errordelay
  81.     exit 1  
  82. fi
  83.  
  84. #   process input-files
  85.  
  86. for src in "$@"; do
  87.  
  88.     case $src in
  89.     *[.][wW][aA][vV]  )
  90.         dst=${src%[.][wW][aA][vV]}.mp3
  91.         if [ -f "$src" ]; then
  92.             if [ $testoverwrite = true -a -f "$dst" ]; then
  93.                 echo \'$dst\' already exists, skipping
  94.         sleep $errordelay
  95.             elif $mp3coder $options `$mp3analyzer "$src"` "$src" "$dst"; then
  96.                 if [ $removesource = true ]; then
  97.                     rm -f "$src"
  98.                 fi
  99.             else
  100.                 echo converting of \'$src\' to \'$dst\' failed
  101.         sleep $errordelay
  102.             fi
  103.         else
  104.             echo No source file \'$src\' found.
  105.         sleep $errordelay
  106.         fi
  107.         ;;
  108.  
  109.     *[.][aA][iI][fF]  )
  110.         dst=${src%[.][aA][iI][fF]}.mp3
  111.         if [ -f "$src" ]; then
  112.             if [ $testoverwrite = true -a -f "$dst" ]; then
  113.                 echo \'$dst\' already exists, skipping
  114.         sleep $errordelay
  115.             elif $mp3coder $options "$src" "$dst"; then
  116.                 if [ $removesource = true ]; then
  117.                     rm -f "$src"
  118.                 fi
  119.             else
  120.                 echo converting of \'$src\' to \'$dst\' failed
  121.         sleep $errordelay
  122.             fi
  123.         else
  124.             echo No source file \'$src\' found.
  125.         sleep $errordelay
  126.         fi
  127.         ;;
  128.  
  129.     *[.][aA][iI][fF][fF] )
  130.         dst=${src%[.][aA][iI][fF][fF]}.mp3
  131.         if [ -f "$src" ]; then
  132.             if [ $testoverwrite = true -a -f "$dst" ]; then
  133.                 echo \'$dst\' already exists, skipping
  134.         sleep $errordelay
  135.             elif $mp3coder $options "$src" "$dst"; then
  136.                 if [ $removesource = true ]; then
  137.                     rm -f "$src"
  138.                 fi
  139.             else
  140.                 echo converting of \'$src\' to \'$dst\' failed
  141.         sleep $errordelay
  142.             fi
  143.         else
  144.             echo No source file \'$src\' found.
  145.         sleep $errordelay
  146.         fi
  147.         ;;
  148.  
  149.     *[.][mM][pP][gG12]  )
  150.         dst=${src%[.][mM][pP][gG12]}.mp3
  151.         if [ -f "$src" ]; then
  152.             if [ $testoverwrite = true -a -f "$dst" ]; then
  153.                 echo \'$dst\' already exists, skipping
  154.         sleep $errordelay
  155.             elif $mp3coder $options "$src" "$dst"; then
  156.                 if [ $removesource = true ]; then
  157.                     rm -f "$src"
  158.                 fi
  159.             else
  160.                 echo converting of \'$src\' to \'$dst\' failed
  161.         sleep $errordelay
  162.             fi
  163.         else
  164.             echo No source file \'$src\' found.
  165.         sleep $errordelay
  166.         fi
  167.         ;;
  168.  
  169.     *[.][mM][pP]3 )
  170.         dst=${src%[.][mM][pP]3}-new-converted-file.${src##*.}
  171.         if [ -f "$src" ]; then
  172.             if [ $testoverwrite = true -a -f "$dst" ]; then
  173.                 echo \'$dst\' already exists, skipping
  174.         sleep $errordelay
  175.             elif $mp3coder $options "$src" "$dst"; then
  176.                 if [ $removesource = true ]; then
  177.                     mv -f "$dst" "$src"
  178.                 fi
  179.             else
  180.                 echo converting of \'$src\' to \'$dst\' failed
  181.         sleep $errordelay
  182.             fi
  183.         else
  184.             echo No source file \'$src\' found.
  185.         sleep $errordelay
  186.         fi
  187.         ;;
  188.  
  189.     * ) # the rest
  190.         echo warning: File extention \'.${src##*.}\' not supported
  191.         sleep $errordelay
  192.         ;;
  193.  
  194.     esac
  195.  
  196. done
  197.